package com.wish.g1.accounting.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.g1.accounting.entity.ReceiptPlan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wish.g1.common.log.annotation.Log;
import com.wish.g1.common.log.enums.BusinessType;
import com.wish.g1.common.security.annotation.RequiresPermissions;
import com.wish.g1.accounting.service.IReceiptPlanService;
import com.wish.g1.common.core.web.controller.BaseController;
import com.wish.g1.common.core.web.domain.AjaxResult;
import com.wish.g1.common.core.utils.poi.ExcelUtil;
import com.wish.g1.common.core.web.page.TableDataInfo;

/**
 * 收款计划Controller
 *
 * @author wish
 * @date 2022-11-27
 */
@RestController
@RequestMapping("/plan")
public class ReceiptPlanController extends BaseController
{
    @Autowired
    private IReceiptPlanService receiptPlanService;

    /**
     * 查询收款计划列表
     */
    // @RequiresPermissions("accounting:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(ReceiptPlan receiptPlan)
    {
        startPage();
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.setEntity(receiptPlan);
        List<ReceiptPlan> list = receiptPlanService.list();
        return getDataTable(list);
    }

    /**
     * 导出收款计划列表
     */
    @RequiresPermissions("accounting:plan:export")
    @Log(title = "收款计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceiptPlan receiptPlan)
    {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.setEntity(receiptPlan);
        List<ReceiptPlan> list = receiptPlanService.list(wrapper);
        ExcelUtil<ReceiptPlan> util = new ExcelUtil<ReceiptPlan>(ReceiptPlan.class);
        util.exportExcel(response, list, "收款计划数据");
    }

    /**
     * 获取收款计划详细信息
     */
    @RequiresPermissions("accounting:plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(receiptPlanService.getById(id));
    }

    /**
     * 新增收款计划
     */
    @RequiresPermissions("accounting:plan:add")
    @Log(title = "收款计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceiptPlan receiptPlan)
    {
        return toAjax(receiptPlanService.save(receiptPlan));
    }

    /**
     * 修改收款计划
     */
    @RequiresPermissions("accounting:plan:edit")
    @Log(title = "收款计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiptPlan receiptPlan)
    {
        return toAjax(receiptPlanService.saveOrUpdate(receiptPlan));
    }

    /**
     * 删除收款计划
     */
    @RequiresPermissions("accounting:plan:remove")
    @Log(title = "收款计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(receiptPlanService.removeByIds(Arrays.asList(ids)));
    }
}
